package org.fusionide.builder.parsers.cfml.tags;

import java.util.Enumeration;

import org.fusionide.builder.parsers.IParserHandler;
import org.fusionide.builder.parsers.ParserException;
import org.fusionide.builder.parsers.cfml.CFMLTag;



public class ElseIf extends CFMLTag {

	public ElseIf(String attributes, int startOffset) {
		super(attributes, startOffset);
	}

	@Override
	public boolean requiresClosingTag() {
		return false;
	}

	@Override
	public boolean acceptsChildren(CFMLTag tag) {
		return false;
	}

	@Override
	public boolean validate(IParserHandler parserHandler) {
		if (super.validate(parserHandler)) {
			if (attributes.trim().equalsIgnoreCase("")) {
				if (parserHandler != null)
					parserHandler.addMarker(new ParserException("<cfelseif> Needs a compairison", ParserException.SEVERITY_ERROR, startLine));
				return false;
			}
		}
		return true;
	}

	@Override
	public boolean setParent(CFMLTag parent) {
		if (!(parent instanceof If))
			return false;

		Enumeration<CFMLTag> children = parent.getChildren();

		while (children.hasMoreElements()) {
			CFMLTag child = children.nextElement();
			if (child instanceof Else)
				return false;
		}

		return super.setParent(parent);
	}
}
